﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace BTCairo
{
    public class GDIPlus : CommonGraphics
    {
        Pen myPen;
        public Pen MyPen
        {
            get { return myPen; }
            set { myPen = value; }
        }

        public GDIPlus(System.Drawing.Graphics _g)
        {
            myGraphic = _g;
            Color color = Color.Black;
            myPen = new Pen(color);
        }
        public GDIPlus(System.Drawing.Graphics _g, InfoGraphic _info)
        {
            myGraphic = _g;
            this.SetInfoGraphic(_info);
        }
        public GDIPlus(GDIPlus temp)
        {
            myGraphic = temp.myGraphic;
            this.SetInfoGraphic(temp.MyInfoGraphic);
        }
       


        public override CommonGraphics CloneCommonGraphic()
        {
            //InfoGraphic info = new InfoGraphic(MyInfoGraphic);
            //GDIPlus clone = new GDIPlus(myGraphic, info);
            GDIPlus clone = new GDIPlus(this);
            return clone;
        }

        public override void SetInfoGraphic(InfoGraphic info)
        {
            MyInfoGraphic = new InfoGraphic(info);
            Color color = Color.FromArgb(info.lineRed, info.lineGreen, info.lineBlue);
            myPen = new Pen(color, info.width);
        }

        public override void DrawLine(double x1, double y1, double x2, double y2)
        {
            myGraphic.DrawLine(new Pen(Color.FromArgb(MyInfoGraphic.lineRed, MyInfoGraphic.lineGreen, MyInfoGraphic.lineBlue)), (int)x1, (int)y1, (int)x2, (int)y2);
        }

        public override void DrawRect(double x, double y, double width, double height)
        {
            if(MyInfoGraphic.fill)////////////////
            {
                Color color = Color.FromArgb(MyInfoGraphic.fillRed, MyInfoGraphic.fillGreen, MyInfoGraphic.fillBlue);
                SolidBrush br = new SolidBrush(color);
                myGraphic.FillRectangle(br, (int)x, (int)y, (int)width, (int)height);
            }
            myGraphic.DrawRectangle(new Pen(Color.FromArgb(MyInfoGraphic.lineRed, MyInfoGraphic.lineGreen, MyInfoGraphic.lineBlue)), (int)x, (int)y, (int)width, (int)height);
        }

        public override void DrawEllipse(double x, double y, double width, double height)
        {
            if (MyInfoGraphic.fill)
            {
                Color color = Color.FromArgb(MyInfoGraphic.fillRed, MyInfoGraphic.fillGreen, MyInfoGraphic.fillBlue);
                SolidBrush br = new SolidBrush(color);
                myGraphic.FillEllipse(br, (int)x, (int)y, (int)width, (int)height);
            }
            myGraphic.DrawEllipse(new Pen(Color.FromArgb(MyInfoGraphic.lineRed, MyInfoGraphic.lineGreen, MyInfoGraphic.lineBlue)), (int)x, (int)y, (int)width, (int)height);
        }

        public override void DrawText(string text, int size, int x, int y)
        {
            Font f = new Font(FontFamily.GenericSansSerif, (float)size);
            Point p = new Point(x, y);
            myGraphic.DrawString(text, f, new SolidBrush(Color.Black), p);
        }
    }
}
